package com.ymatou.operate.trading.api.service;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ymt.base.YmatouBaseCall;
import com.ymttest.common.entitie.PostPayResult;
import com.ymttest.utils.EnvSetup;

/**
 * 批量申请补款接口Call FreeMaker Template自动生成代码
 */
public class BatchApplyForPostPayCall extends YmatouBaseCall {
	private static String opurl = "api/Seller/BatchApplyForPostPay";

	public BatchApplyForPostPayCall() {
		super(EnvSetup.getSystemUrl("api_order_operate"), opurl, "POST", "JSON");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept", "text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	/**
	 * 获取Code
	 * 
	 * @return
	 */
	public String getCode() {
		String Code = null;
		try {
			Code = new JSONObject(getReturnData()).getString("Code");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}

	/**
	 * 获取BCode
	 * 
	 * @return
	 */
	public String getBCode() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("BCode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Msg
	 * 
	 * @return
	 */
	public String getMsg() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("Msg");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Data
	 * 
	 * @return
	 */
	public JSONObject getData() {
		JSONObject Data = null;
		try {
			Data = new JSONObject(getReturnData()).getJSONObject("Data");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Data;
	}

	/**
	 * 获取PostPayResultList
	 * 
	 * @return
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public ArrayList<PostPayResult> getPostPayResultList() {
		ArrayList<PostPayResult> list = new ArrayList<PostPayResult>();
		try {
			String rd = getData().getString("PostPayResultList");
			Gson gson = new Gson();
			list = gson.fromJson(rd, new TypeToken<ArrayList<PostPayResult>>() {
			}.getType());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 获取SuccessNum
	 * 
	 * @return
	 */
	public int getSuccessNum() {
		int SuccessNum = 0;
		try {
			SuccessNum = getData().getInt("SuccessNum");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return SuccessNum;
	}

	/**
	 * 获取postPayIdList
	 * 
	 * @return postPayIdList
	 */
	public ArrayList<String> getPostPayId() {
		ArrayList<PostPayResult> list = this.getPostPayResultList();
		ArrayList<String> postPayIdList = new ArrayList<String>();
		try {
			for (PostPayResult rt : list) {
				String postPayId = rt.getPostPayId();
				postPayIdList.add(postPayId);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return postPayIdList;
	}
}
